package com.gmgx.hrms.biz.impl;

import com.gmgx.hrms.biz.TransferBiz;
import com.gmgx.hrms.dao.TransferDao;
import com.gmgx.hrms.dao.impl.TransferDaoImpl;
import com.gmgx.hrms.entity.Transfer;
import com.mysql.cj.protocol.Resultset;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

public class TransferBizImpl implements TransferBiz {
private TransferDao transferDao=new TransferDaoImpl();
    @Override
    public boolean applyTransferForEmp(Transfer transfer) {
        if(transferDao.queryTransferByEmpid(transfer.getTransfer_emp().getEmp_id())){
            System.out.println("有未处理的调岗审批记录 ，无法调岗");
            return false;
        }else{
            if(transfer.getTransfer_time().isAfter(LocalDate.now())){
                if((transfer.getTransfer_emp().getEmp_role().getRole_id()==transfer.getTransfer_role().getRole_id())&&(transfer.getTransfer_emp().getEmp_dept().getDept_id()==transfer.getTransfer_dept().getDept_id())){
                    System.out.println("要调岗的部门和角色跟当前一致，无需调岗");
                    return false;
                }else{
                  return transferDao.addTransferForEmp(transfer);
                }
            }else{
                System.out.println("调岗的日期不能早于当前时间");
                return false;
            }
        }
    }

    @Override
    public List<Transfer> getTransferByDeptidForManager(int deptid) {

        return transferDao.queryTransferByDeptidForManager(deptid);
    }

    @Override
    public boolean editTransferForManager(int transferid, String status) {
        return transferDao.updateTransferByTransferidForManager(transferid,status);
    }
}
